package main

import (
	"fmt"
	helper "gin-ranking/common/zinx/tcp/lock/handler"
	"gin-ranking/common/zinx/znet"
	"gin-ranking/pkg/db"
	"gin-ranking/pkg/logs"
	"gin-ranking/router"
	"gin-ranking/setting"
)

// 交叉编译 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go
// https://golang.halfiisland.com/deb.html#%E6%96%87%E4%BB%B6%E5%A4%84%E7%90%86
// go mod init gin-ranking
// go get -u github.com/gin-gonic/gin
const defaultConfFile = "./conf/config.ini"

func StartTcpServer() {
	// 1 创建一个server句柄, 使用Zinx的api
	server := znet.NewServer("[Zinx V0.6]")

	// 2 给当前 zinx 框架添加一个自定义的router
	server.AddRouter(0, &helper.PingRouter{})

	// 3 启动server
	server.Server()
}

func main() {

	//// 反射
	//user := reflect.User{1, "Aceld", 18}
	//reflect.DoFiledAndMethod(user)

	//// 时间处理
	//str := util.Now()
	//format := util.DateTimeFormat(util.Offset(util.CurrentTime(), util.Month, 1))
	//println(format, str)
	//between := util.Between(util.CurrentTime(), util.ParseDate("2024-10-19 17:36:39"), util.Day)
	//println(between)

	confFile := defaultConfFile
	// 初始化配置
	err := setting.Init(confFile)

	if err != nil {
		fmt.Printf("load config file failed, err:%v\n", err)
		return
	}

	// 初始化数据库
	db.InitMysql(setting.Conf.MysqlConfig)

	//if err != nil {
	//	fmt.Printf("init mysql failed, err:%v\n", err)
	//	return
	//}

	// 程序退出关闭数据库链接
	//defer dao.CloseMysql()

	go StartTcpServer()

	logs.Poster()
	r := router.Router()
	err = r.Run(fmt.Sprintf(":%d", setting.Conf.Port))
	if err != nil {
		fmt.Printf("start imServer failed, err:%v\n", err)
	}

}
